<?php
	
	class Card_Model extends CI_Model
	{
		public function __construct()
		{
			$this->load->database();
		} //end index

//---------------------------------------------------------------------------------------------------------------------------------------//
// 															 SET FUNCTIONS                                                               //
//---------------------------------------------------------------------------------------------------------------------------------------//
		function set_deck($suit_id, $face)
		{
			$data = array(
					'suit_id' => $suit_id,
					'face' => $face
				);
			$this->db->insert('deck', $data);
		}

		function set_hand($player, $suit_id, $face)
		{
			$data = array(
					'player' => $player,
					'suit_id' => $suit_id,
					'face' => $face
				);
			$this->db->insert('hand', $data);
		}

		function set_trump($suit_id, $face)
		{
			$data = array(
					'suit_id' => $suit_id,
					'face' => $face
				);
			$this->db->insert('trump', $data);
		}

		function set_table($suit_id, $face)
		{
			$data = array(
					'suit_id' => $suit_id,
					'face' => $face
				);
			$this->db->insert('field', $data);
		}

		function deal($suit_id, $face)
		{
			$this->db->where('suit_id', $suit_id);
			$this->db->where('face', $face);
			$this->db->delete('deck');
		}

		function remove_from($player, $suit_id, $face)
		{
			$this->db->where('player', $player);
			$this->db->where('suit_id', $suit_id);
			$this->db->where('face', $face);
			$this->db->delete('hand');
		}

		function empty_table()
		{
			$this->db->empty_table('field');
		}

		function clear_data($name)
		{
			$this->db->empty_table($name);
		}

//---------------------------------------------------------------------------------------------------------------------------------------//
// 															 GET FUNCTIONS                                                               //
//---------------------------------------------------------------------------------------------------------------------------------------//
		function get_cards()
		{
			$this->db->select('suit_id, face');
			$query = $this->db->get('cards');
			return $query->result_array();
		} 

		function get_deck()
		{
			$this->db->select('suit_id, face');
			$query = $this->db->get('deck');
			return $query->result_array();
		}

		function get_table()
		{
			$this->db->select('suit_id, face');
			$query = $this->db->get('field');
			return $query->result_array();
		} 

		function get_hand($player)
		{
			$this->db->where('player', $player);
			$this->db->select('suit_id, face');
			$query = $this->db->get('hand');
			return $query->result_array();
		} 

		function get_trump()
		{
			$this->db->select('suit_id, face');
			$query = $this->db->get('trump');
			return $query->result_array();
		}
	}

?>